package com.sumainfor.pc.dev.controller;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.dev.dao.MovableMapper;
import com.sumainfor.pc.dev.service.impl.MovableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  活动管理
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-04-03 15:05
 **/
@Controller
@RequestMapping("/movable")
public class MovableController {
    @Autowired
    MovableService movableService;

    /**
     * 功能描述:
     * 获取首页活动
     * @Author zhoucong
     * @Date 2019/3/10 14:15
     */
    @ResponseBody
    @GetMapping("/getMovableList")
    public JsonResult getMovableList(){
        Map<String,Object>params=new HashMap<String,Object>();
        Pager pager=new Pager();
        params.put("delfg",0);
        params.put("pageno",0);
        params.put("pagesize",2);
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=movableService.getMovableListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getMovableList=movableService.getMovableList(params);
        return pageUtils.getJsonResult(getMovableList, params, cout);
    }

    /**
    * <p>
    * 增加活动
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/insertMovable")
    public JsonResult insertMovable(@RequestBody Map<String,Object> params){
        return movableService.insertMovable(params);
    }

    /**
    * <p>
    * 编辑活动
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/updateMovable")
    public JsonResult updateMovable(@RequestBody Map<String,Object> params){
        return  movableService.updateMovable(params);
    }


}
